﻿using Shinva.LADModel.Abstractions;
using Shinva.Variables.Interface;
using Shinva.Variables.Models;
using Shinva.Variables.Type.bit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shinva.LADModel.Type.Mathfunctions
{
    public class Div<T> : ElementNodeBase where T : IPlcMember
    {
        public T in1 { get; set; }
        public T in2 { get; set; }
        public T outVal { get; set; } //实为out

        public override PlcBool EN
        {
            get
            {
                return en;
            }
            set
            {
                en = value;
            }
        }
        public override PlcBool ENO
        {
            get
            {

                eno.Value = en.Value && DivValue();
                return eno;
            }
            set
            {
                eno = value;
            }
        }
        public Div()
        {
            Name = "Div";
            variableTableInterface.AddVariable("in1", StorageType.Input);
            variableTableInterface.AddVariable("in2", StorageType.Input);
            variableTableInterface.AddVariable("out", StorageType.Output);

            in1 = variableTableInterface.GetVariableValue<T>("in1");
            in2 = variableTableInterface.GetVariableValue<T>("in2");
            outVal = variableTableInterface.GetVariableValue<T>("out");
        }
        public override IPlcMember GetInterfaceVariableByName(string name)
        {
            if (name == "out") return outVal;
            else return variableTableInterface.GetVariableValue<IPlcMember>(name);
        }
        public bool DivValue()
        {
            if (in1 == null || in2 == null)
            {
                return false;
            }
            return false;
        }
    }
}
